

**** Table H.14: district-level 
use "$datadir\ewallet\merchants_reshape_week.dta" , clear 

	g onplatform = transaction > 0
		
	egen merchant_id = group(merchantid)
	egen districttime = group(districtid time)
	egen industrytime = group(industry time)

	bys industryid districttime : egen amount_jt = total(amount) 
	bys industryid districttime : egen transaction_jt = total(transaction) 
	bys industryid districttime : egen onplatform_jt = total(onplatform) 
	
	xtset merchantid time
	
	foreach var in amount transaction onplatform {
		g lag_`var'_jt = l.`var'_jt
		g lag_`var' = l.`var'
		g lag_`var'_jt_1 = lag_`var'_jt - lag_`var'
		
		g ln_lag_`var' = ln(1+lag_`var')
		g ln_lag_`var'_jt_1 = ln(1+lag_`var'_jt_1)
		g ln_`var' = ln(1+`var')
	}
	
	
	foreach var in ln_lag_amount  ln_lag_amount_jt_1 ln_amount ln_lag_transaction  ln_lag_transaction_jt_1 ln_transaction {
	bys time: egen m_`var'=mean(`var')
	bys time: egen sd_`var'=sd(`var')
	gen `var'_z=(`var'-m_`var')/sd_`var'
	drop m_`var' sd_`var'
	sum `var'_z
	}
	*this is purely to make the code run
	rename ln_lag_amount_jt_1_z ln_lag_amount_z_jt_1
	rename ln_lag_transaction_jt_1  ln_lag_transaction_z_jt_1
	
	
	*** amount
	foreach var in  amount {
		reg ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1 , cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_1.tex", dec(3) replace
		reghdfe ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1 , a(merchant_id ) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_1.tex", dec(3) append
		reghdfe ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1, a(merchant_id districttime) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_1.tex", dec(3) append
		reghdfe ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1, a(merchant_id districttime industrytime) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_1.tex", dec(3) append
	}
	
	*** transactions
	foreach var in  transaction {
		reg ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1 , cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_2.tex", dec(3) replace
		reghdfe ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1 , a(merchant_id ) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_2.tex", dec(3) append
		reghdfe ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1 , a(merchant_id districttime) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_2.tex", dec(3) append
		reghdfe ln_`var' ln_lag_`var' c.ln_lag_`var'_jt_1, a(merchant_id districttime industrytime) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_2.tex", dec(3) append
	}
	
	*** On platform
	foreach var in  onplatform {
		reg `var' lag_`var' c.ln_lag_`var'_jt_1 , cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_3.tex", dec(3) replace
		reghdfe `var' lag_`var' c.ln_lag_`var'_jt_1 , a(merchant_id ) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_3.tex", dec(3) append
		reghdfe `var' lag_`var' c.ln_lag_`var'_jt_1 , a(merchant_id districttime) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_3.tex", dec(3) append
		reghdfe `var' lag_`var' c.ln_lag_`var'_jt_1 , a(merchant_id districttime industrytime) cluster(districtid)
		outreg2 using "$outputdir_tab\Table_H_14_3.tex", dec(3) append
	}
	 
	
	
	
